﻿using System;
using System.Data;
using System.Collections.Generic;
using HsTec.Mobile.Green.Model;
namespace HsTec.Mobile.Green.BLL
{
    /// <summary>
    /// 业务逻辑类Weight 的摘要说明。
    /// </summary>
    public class WeightBLL
    {
        private readonly HsTec.Mobile.Green.DAL.WeightDAL dal = new HsTec.Mobile.Green.DAL.WeightDAL();
        public WeightBLL()
        { }
        #region  成员方法
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string W_IDs)
        {
            return dal.Exists(W_IDs);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(HsTec.Mobile.Green.Model.Weight model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int Update(HsTec.Mobile.Green.Model.Weight model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public int Delete(string W_IDs)
        {

            return dal.Delete(W_IDs);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public HsTec.Mobile.Green.Model.Weight GetModel(int W_ID)
        {

            return dal.GetModel(W_ID);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataView GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataView GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<HsTec.Mobile.Green.Model.Weight> GetModelList(string strWhere)
        {
            DataView ds = dal.GetList(strWhere);
            return DataTableToList(ds.Table);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<HsTec.Mobile.Green.Model.Weight> DataTableToList(DataTable dt)
        {
            List<HsTec.Mobile.Green.Model.Weight> modelList = new List<HsTec.Mobile.Green.Model.Weight>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                HsTec.Mobile.Green.Model.Weight model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new HsTec.Mobile.Green.Model.Weight();
                    if (dt.Rows[n]["W_ID"].ToString() != "")
                    {
                        model.W_ID = int.Parse(dt.Rows[n]["W_ID"].ToString());
                    }
                    model.Years = dt.Rows[n]["Years"].ToString();
                    if (dt.Rows[n]["Weight1"].ToString() != "")
                    {
                        model.Weight1 = decimal.Parse(dt.Rows[n]["Weight1"].ToString());
                    }
                    if (dt.Rows[n]["Weight2"].ToString() != "")
                    {
                        model.Weight2 = decimal.Parse(dt.Rows[n]["Weight2"].ToString());
                    }
                    if (dt.Rows[n]["Weight3"].ToString() != "")
                    {
                        model.Weight3 = decimal.Parse(dt.Rows[n]["Weight3"].ToString());
                    }
                    if (dt.Rows[n]["Weight4"].ToString() != "")
                    {
                        model.Weight4 = decimal.Parse(dt.Rows[n]["Weight4"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataView GetAllList()
        {
            return GetList("");
        }

        #endregion  成员方法
    }
}

